package com.lanou.web.controller;

import com.lanou.entity.ContentImg;
import com.lanou.entity.Item;
import com.lanou.entity.TbItemDesc;
import com.lanou.service.ItemDescService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class ItemDescController {
    @Autowired
    private ItemDescService itemDescService;

    @ApiOperation("展示商品信息")
    @GetMapping("/item/{id}")
    public String showItem(@PathVariable("id") Long id, Model model){
        Item item = itemDescService.showItemById(id);
        model.addAttribute("item",item);
        return "item";
    }

    @ApiOperation("展示商品描述")
    @GetMapping("/item/desc/{id}")
    @ResponseBody
    public String showItemDesc(@PathVariable("id") Long id){
        TbItemDesc tbItemDesc = itemDescService.showItemDescById(id);
        String itemDesc = tbItemDesc.getItemDesc();
        return itemDesc;
    }


    @ApiOperation("展示商品规格参数")
    @GetMapping("/item/param/{id}")
    @ResponseBody
    public String showItemParam(@PathVariable("id") Long id){
        String itemParamItem = itemDescService.showItemParamById(id);
        return itemParamItem;
    }

    @ApiOperation("商品详情页面边栏广告展示")
    @GetMapping("/item/desc/img")
    @ResponseBody
    public List<ContentImg> showDescImg(){
        List<ContentImg> contentImgList = itemDescService.showDescImg();
        return contentImgList;
    }


}
